home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_3 / phoonsrc / dtime.c < prev    next >
C/C++ Source or Header  |  1994-02-23  |  2KB  |  68 lines

  1. #ifndef lint
  2. static char rcsid[] =
  3.     "@(#) $Header: dtime.c,v 1.3 88/08/26 22:29:38 jef Exp $ (LBL)";
  4. #endif
  5.  
  6. /*
  7. ** Copyright (C) 1988 by Jef Poskanzer.
  8. **
  9. ** Permission to use, copy, modify, and distribute this software and its
  10. ** documentation for any purpose and without fee is hereby granted, provided
  11. ** that the above copyright notice appear in all copies and that both that
  12. ** copyright notice and this permission notice appear in supporting
  13. ** documentation.  This software is provided "as is" without express or
  14. ** implied warranty.
  15. */
  16.  
  17. /* dtime.c - extracted from the phoon/libtws package
  18. */
  19.  
  20.  
  21. #include "tws.h"
  22. #include <sys/types.h>
  23. #include <time.h>
  24.  
  25. unsigned long atime( unsigned long * );
  26. struct tm * alocaltime( unsigned long *);
  27. struct tws *adlocaltime( unsigned long * clock);
  28.  
  29. extern short gmtoffset; /* hmmm */
  30.  
  31. struct tws *
  32.   dtwstime( )
  33. {
  34.     unsigned long clock;
  35.  
  36.     (void) atime( &clock );
  37.     return ( adlocaltime( &clock ) );
  38. }
  39.  
  40. struct tws *
  41.   adlocaltime( unsigned long * clock)
  42. {
  43.     register struct tm *tm;
  44.     static struct tws tw;
  45.  
  46.     if ( clock == NULL )
  47.     return ( NULL );
  48.     tw.tw_flags = TW_NULL;
  49.  
  50.     tm = alocaltime( clock );
  51.  
  52.     tw.tw_sec = tm -> tm_sec;
  53.     tw.tw_min = tm -> tm_min;
  54.     tw.tw_hour = tm -> tm_hour;
  55.     tw.tw_mday = tm -> tm_mday;
  56.     tw.tw_mon = tm -> tm_mon;
  57.     tw.tw_year = tm -> tm_year;
  58.     tw.tw_wday = tm -> tm_wday;
  59.  
  60.     tw.tw_zone = -gmtoffset;
  61.  
  62.     tw.tw_flags &= ~TW_SDAY;
  63.     tw.tw_flags |= TW_SEXP;
  64.     tw.tw_clock = *clock + (8 * 365 + 2) * 24 * 3600;
  65.  
  66.     return ( &tw );
  67. }
  68.